package com.suncreate.zhtz.iot.tool;

import com.suncreate.zhtz.iot.model.ScWarningStrategy;
import com.suncreate.zhtz.iot.service.ScWarningStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CheckAlarmUtil {
    @Autowired
    private ScWarningStrategyService scWarningStrategyService;

    /**
     * 数据异常判断
     * @param str
     * @param list
     * @return
     */
    public static Map<String,Object> checkData(String str, List<ScWarningStrategy> list){
        /**
         * 0 正常
         * 1 轻微异常
         * 2 中等异常
         * 3 严重异常
         */
        Map<String,Object> resultMap = new HashMap<>();

        Integer checkDataStart = DataDictionary.CHECK_DATA_STATUS.NORMAL;
        resultMap.put("checkDataStart",checkDataStart);
        resultMap.put("alarmMessage","正常");

        if(!StringUtils.isEmpty(list)){
            ScWarningStrategy scWarningStrategy = list.get(0);
            //轻微异常判断
            String weakAlarm = scWarningStrategy.getWeakalarm();
            if(str.equals(weakAlarm)){
                checkDataStart = DataDictionary.CHECK_DATA_STATUS.MINOR;
                resultMap.put("checkDataStart",checkDataStart);
                resultMap.put("alarmMessage","轻微异常");
            }

            //中等异常判断
            String middleAlarm = scWarningStrategy.getMiddlealarm();
            if(str.equals(middleAlarm)){
                checkDataStart = DataDictionary.CHECK_DATA_STATUS.MODERATE;
                resultMap.put("checkDataStart",checkDataStart);
                resultMap.put("alarmMessage","中等异常");
            }

            //严重异常判断
            String hardAlarm = scWarningStrategy.getHardalarm();
            if(str.equals(hardAlarm)){
                checkDataStart = DataDictionary.CHECK_DATA_STATUS.CRITICAL;
                resultMap.put("checkDataStart",checkDataStart);
                resultMap.put("alarmMessage","严重异常");
            }

        }
        return resultMap;
    }
}
